﻿//-----------------------------------------------------------------------
// <copyright file="DataBagValueBase.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.DataBag
{
    /// <summary>
    /// Data bag value base class.
    /// </summary>
    public abstract class DataBagValueBase : IDataBagValue
    {
        #region Fields - Private

        /// <summary>
        /// Parent of this object.
        /// </summary>
        private DataBag parent;

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor.
        /// </summary>
        public DataBagValueBase()
        {
            this.parent = null;
        }

        #endregion

        #region Properties - Public

        /// <summary>
        /// Gets the type of value.
        /// </summary>
        public abstract DataBagValueType Type
        {
            get;
        }

        /// <summary>
        /// Gets the value of the data bag value as an object.
        /// </summary>
        public abstract object ObjectValue
        {
            get;
        }

        #endregion

        #region Properties - Internal

        /// <summary>
        /// Gets or sets the parent data bag.
        /// </summary>
        internal DataBag Parent
        {
            get
            {
                return this.parent;
            }

            set
            {
                this.parent = value;
            }
        }

        #endregion

        #region Methods - Public

        /// <summary>
        /// Clone this data bag value by creating a deep copy.
        /// </summary>
        /// <returns>Returns a copy of the data bag value.</returns>
        public abstract IDataBagValue Clone();

        #endregion

        #region Methods - Protected

        /// <summary>
        /// Trigger the value changed event on our parent data bag.
        /// </summary>
        protected void TriggerValueChanged()
        {
            if (this.parent != null)
            {
                this.parent.ValueChanged(this);
            }
        }

        #endregion
    }
}
